package com.jmc.calls;


import java.io.Serializable;
import java.sql.SQLException;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.CommandCall;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;

public class TestProgramCallCTE030 implements Serializable{

	public static void main(String[] args) throws SQLException{
		// Call programs on system "Hal"
		AS400 as400 = new AS400("www.coinse.com.ar", "jfb", "jfb88");
		ProgramCall pgm = new ProgramCall( as400 );
		try
		{
		//Agrego la Libreria de Datos
		CommandCall cmd = new CommandCall( as400 );
		if (cmd.run("ADDLIBLE libivasd1")!=true)
		{
		// Note that there was an error
		System.out.println( "program failed!" );
		}
		cmd.run("CHGDTAARA  DTAARA(*LDA (2 1)) VALUE(' ')");
		cmd.run("CHGDTAARA  DTAARA(*LDA (11 1)) VALUE('0')");  
		cmd.run("CHGDTAARA  DTAARA(*LDA (12 5)) VALUE('02005')");
		cmd.run("CHGDTAARA  DTAARA(*LDA (17 1)) VALUE('0')");  
		cmd.run("CHGDTAARA  DTAARA(*LDA (18 3)) VALUE('030')");  
		cmd.run("CHGDTAARA  DTAARA(*LDA (21 3)) VALUE('060')");  
		cmd.run("CHGDTAARA  DTAARA(*LDA (300 1)) VALUE('0')"); 
		
		// Show the messages (returned whether or not there was an error)
		AS400Message[] messagelistCommand = cmd.getMessageList();
		for (int i=0; i < messagelistCommand.length; i++)
		{
		// show each message
		System.out.println(messagelistCommand[i].getText() );
		}
			
		// Initialize the name of the program to run
		String progName = "/QSYS.LIB/LIBIVA.LIB/CTE040.PGM";
		// Setup the 3 parameters
		
		// First parameter is to input a name

		pgm.setProgram( progName );
		// Run the program
		if (pgm.run()!=true)
		{
		// Note that there was an error
		System.out.println( "program failed!" );
		// Show the messages
		AS400Message[] messagelist = pgm.getMessageList();
		for (int i=0; i < messagelist.length; i++)
		{
		// show each message
		System.out.println( messagelist[i] );
		}
		}
		else
		{
		AS400Text text = null;
		}
		}
		catch (Exception e)
		{
		System.out.println( "Program " + pgm.getProgram() + " did not run!" );
		e.printStackTrace();
		}
		// done with the system
		as400.disconnectAllServices();

	
	}
}
